﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using OF.Common;

namespace OF.Web.user.controls
{
    /// <summary>
    /// Handler 的摘要说明
    /// </summary>
    public class service : IHttpHandler
    {
        BLL.Addr.AreaCache bll_cache = new BLL.Addr.AreaCache();
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string pid = context.Request.QueryString["pid"];
            if (!string.IsNullOrWhiteSpace(pid))
                GetAreaList(pid, context);

            string areaid = context.Request.QueryString["areaid"];
            if (!string.IsNullOrWhiteSpace(areaid))
                GetSchoolList(areaid, context);
        }

        #region 地区级联查询

        public void GetAreaList(string pid, HttpContext context)
        {
            List<OF.Model.Area> modellist = bll_cache.GetAreaByPid(Convert.ToInt32(pid)).ToList();
            if (modellist != null)
                context.Response.Write(Json.Serialize(modellist));
            else
                context.Response.Write("no");


        }

        #endregion

        #region 获取区下面的学校

        public void GetSchoolList(string areaid, HttpContext context)
        {

            List<OF.Model.School> modellist = bll_cache.GetSchoolsByAreaId(Convert.ToInt32(areaid)).ToList();
            if (modellist != null)
                context.Response.Write(Json.Serialize(modellist));
            else
                context.Response.Write("no");



        }

        #endregion

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}